package com.mornd.gulimall.coupon.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mornd.gulimall.coupon.entity.SeckillSkuRelation;
import com.mornd.gulimall.coupon.mapper.SeckillSkuRelationMapper;
import com.mornd.gulimall.coupon.service.ISeckillSkuRelationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 秒杀活动商品关联 服务实现类
 * </p>
 *
 * @author mornd
 * @since 2023-08-05
 */
@Service
public class SeckillSkuRelationServiceImpl extends ServiceImpl<SeckillSkuRelationMapper, SeckillSkuRelation> implements ISeckillSkuRelationService {

    @Override
    public IPage<SeckillSkuRelation> pageList(SeckillSkuRelation seckillSkuRelation) {
        IPage<SeckillSkuRelation> page = new Page<>(seckillSkuRelation.validPageNum(), seckillSkuRelation.validPageSize());
        LambdaQueryWrapper<SeckillSkuRelation> qw = Wrappers.<SeckillSkuRelation>lambdaQuery();
        if(seckillSkuRelation.getId() != null) {
            qw.eq(SeckillSkuRelation::getId, seckillSkuRelation.getId());
            qw.or().eq(SeckillSkuRelation::getPromotionSessionId, seckillSkuRelation.getId());
        }
        qw.orderByAsc(SeckillSkuRelation::getSeckillSort);
        super.page(page, qw);
        return page;
    }
}
